package com.koron.css2.meterService.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.MeterBoreBean;
import com.koron.css2.baseConfig.bean.MeterFactoryBean;
import com.koron.css2.baseConfig.bean.MeterModelBean;
import com.koron.css2.baseConfig.mapper.*;
import com.koron.css2.baseConfig.queryBean.MeterModelQueryBean;
import com.koron.css2.baseConfig.vo.MeterModelVO;
import com.koron.css2.baseConfig.vo.SelectVO;
import com.koron.css2.meterService.bean.MsChangeHistoryBean;
import com.koron.css2.meterService.bean.MsInfoBean;
import com.koron.css2.meterService.bean.MsInfoChangeBean;
import com.koron.css2.meterService.bean.MsInfoChangeDetailBean;
import com.koron.css2.meterService.bean.query.MsInfoQueryBean;
import com.koron.css2.meterService.dto.MsInfoDto;
import com.koron.css2.meterService.mapper.*;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.DateUtils;
import com.koron.util.Tools;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.beans.BeanUtils;
import org.swan.bean.MessageBean;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 水表变更添加
 * @author 周利斌
 *
 */
public class WmChgAdd implements ServerInterface{
	
	private static Logger log = LogManager.getLogger(WmChgAdd.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		
		MessageBean<Map> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "添加成功", Map.class);
		try {
			MsInfoChangeBean bean = JsonUtils.objectToPojo(req.getData(), MsInfoChangeBean.class);
			MsInfoChangeMapper mapper = factory.getMapper(MsInfoChangeMapper.class);
			MsInfoTempMapper msInfoMapper = factory.getMapper(MsInfoTempMapper.class);
			MsInfoChangeDetailMapper detailMapper = factory.getMapper(MsInfoChangeDetailMapper.class);
			List<MsInfoBean> msInfos = bean.getMsInfos();
			bean.setCreateInfo(userInfo);
			int updateAmount = 0;
			int deleteAmount = 0;
			for(MsInfoBean msInfo : msInfos) {
				String billNo = mapper.selectProcessNotEnd(msInfo.getMeterNo(),bean.getId());
				if(billNo!= null) {
					return MessageBean.create(Constant.MESSAGE_INT_FAIL, "该水表存在其它状态的单据", void.class);
				}
			}
			if(msInfoBeanIsRepeat(msInfos)) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "当前变更单据存在重复表身码", void.class);
			};
			MsInfoBean repeat = imeiIsRepeat(msInfos);
			if(repeat != null) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "当前变更单据存在重复的IMEI号：" + repeat.getImei(), void.class);
			};
			repeat = imsiIsRepeat(msInfos);
			if(repeat != null) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "当前变更单据存在重复的IMSI号：" + repeat.getImsi(), void.class);
			};
			for(MsInfoBean msInfo : msInfos) {				
				MsInfoChangeDetailBean detail = new MsInfoChangeDetailBean();
				if(StringUtils.isBlank(msInfo.getMeterModel())) {
					return MessageBean.create(Constant.MESSAGE_INT_FAIL, "水表型号不能为空", void.class);
				}
				if(StringUtils.isNotBlank(msInfo.getImei())) {
					msInfo.setImei(msInfo.getImei().trim());
					int iCount = msInfoMapper.checkImei(msInfo.getImei(), msInfo.getMeterNo());
					if (iCount > 0){
						return MessageBean.create(Constant.MESSAGE_INT_FAIL, "水表库中存在相同的水表IMEI号(" + msInfo.getImei() + ")", Void.class);
					}
				}
				if(StringUtils.isNotBlank(msInfo.getImsi())) {
					msInfo.setImsi(msInfo.getImsi().trim());
					int iCount = msInfoMapper.checkImsi(msInfo.getImsi(), msInfo.getMeterNo());
					if (iCount > 0){
						return MessageBean.create(Constant.MESSAGE_INT_FAIL, "水表库中存在相同的水表IMSI号(" + msInfo.getImsi() + ")", Void.class);
					}
				}
				detail.setChangeId(bean.getId());
				detail.setId(Tools.getObjectId());
				detail.setSim(msInfo.getSim());
				detail.setMeterNo(msInfo.getMeterNo());
				detail.setOperateType(msInfo.getOperateType());
				String msInfoId = Tools.getObjectId();
				msInfo.setCreateName(userInfo.getUserInfo().getName());
				msInfo.setId(msInfoId);
				Integer check = msInfoMapper.checkFactoryNo(msInfo.getMeterNo(),msInfo.getFactoryNo());
				if(check!=null && check>0) {
					return MessageBean.create(Constant.MESSAGE_INT_FAIL, "表身码："+msInfo.getFactoryNo()+"已存在", void.class);
				}

				msInfoMapper.addMsInfoTemp(msInfo);
				detail.setMsInfoId(msInfoId);
				detail.setOperateType(msInfo.getOperateType());
				detailMapper.insert(detail);
				if(msInfo.getOperateType() == 1) {
					updateAmount ++;
				}
				if(msInfo.getOperateType() == 2) {
					deleteAmount ++;
				}
			}
			bean.setDeleteAmount(deleteAmount);
			bean.setUpdateAmount(updateAmount);
			bean.setBillDate(new Date());
			bean.setBillNo(Tools.getBillNo(factory, "ms_info_change"));
			mapper.insert(bean);
			Map<String, String> data = new HashMap<String, String>();
			data.put("id", bean.getId());
			info.setData(data);

			//计算变更历史
			Map<String, String> meterStatus = Tools.mapDicByCode(factory, "MMS");
			Map<String, String> meterForms = Tools.mapDicByCode(factory, "MMF");
			Map<String, String> commOperators = Tools.mapDicByCode(factory, "TXS");
			Map<String, String> transmittalModel = Tools.mapDicByCode(factory, "TPW");
			Map<String, String> meterTypes = Tools.mapDicByCode(factory, "MMT");
			Map<String, String> meterPatterns = Tools.mapDicByCode(factory, "MMP");
			Map<String, String> meterSensors = Tools.mapDicByCode(factory, "MSS"); //水表传感器
			Map<String, String> protocols = Tools.mapDicByCode(factory, "XXGY"); //下行规约
			//水表型号
			MeterModelMapper meterModelMapper = factory.getMapper(MeterModelMapper.class);
			List<MeterModelVO> modelList = meterModelMapper.selectMeterModelList(new MeterModelQueryBean());
			//过滤出变更水表
			List<MsInfoBean> msInfoBeans = msInfos.stream().filter(dto -> dto.getOperateType() == 1).collect(Collectors.toList());
			List<String> meterNos = msInfoBeans.stream().map(MsInfoBean::getMeterNo).collect(Collectors.toList());
			List<MsInfoDto> msInfoDtoListBefore = new ArrayList<MsInfoDto>();
			if (meterNos.size() > 0){
				MsInfoMapper msInfoDao = factory.getMapper(MsInfoMapper.class);
				MsInfoQueryBean msInfoQueryBean = new MsInfoQueryBean();
				msInfoQueryBean.setMeterNos(meterNos);
				msInfoDtoListBefore = msInfoDao.selectMsInfoList(msInfoQueryBean);
				msInfoDtoListBefore.forEach(dto -> {
					//传输方式
					dto.setTransmittalModelName(transmittalModel.get(dto.getTransmittalModel()));
					// 水表状态
					dto.setMeterStatusName(meterStatus.get(dto.getMeterStatus()));
					// 水表形态
					dto.setMeterFormName(meterForms.get(dto.getMeterForm()));
					// 水表类型
					dto.setMeterTypeName(meterTypes.get(dto.getMeterType()));
					// 通讯商
					dto.setCommOperatorName(commOperators.get(dto.getCommOperator()));
					// 水表型式
					dto.setMeterPatternName(meterPatterns.get(dto.getMeterPattern()));
					// 水表传感器
					dto.setMeterSensorName(meterSensors.get(dto.getMeterSensor()));
					//下行规约
					dto.setProtocolName(protocols.get(dto.getProtocol()));

					if(StringUtils.isNotBlank(dto.getMeterModel())) {
						dto.setMeterModelName(modelList.stream().filter(y-> y.getId().equals(dto.getMeterModel())).findFirst().orElse(new MeterModelVO()).getModelName());
					}else {
						dto.setMeterModelName("");
					}
					setMsInfo(factory,dto,userInfo);
				});
			}
			List<MsInfoDto> msInfoDtoListAfter = msInfoBeans.stream().map(dto -> {
				MsInfoDto msInfoDto = new MsInfoDto();
				BeanUtils.copyProperties(dto, msInfoDto);
				//传输方式
				msInfoDto.setTransmittalModelName(transmittalModel.get(dto.getTransmittalModel()));
				// 水表状态
				msInfoDto.setMeterStatusName(meterStatus.get(dto.getMeterStatus()));
				// 水表形态
				msInfoDto.setMeterFormName(meterForms.get(dto.getMeterForm()));
				// 水表类型
				msInfoDto.setMeterTypeName(meterTypes.get(dto.getMeterType()));
				// 通讯商
				msInfoDto.setCommOperatorName(commOperators.get(dto.getCommOperator()));
				// 水表型式
				msInfoDto.setMeterPatternName(meterPatterns.get(dto.getMeterPattern()));
				// 水表传感器
				msInfoDto.setMeterSensorName(meterSensors.get(dto.getMeterSensor()));
				//下行规约
				msInfoDto.setProtocolName(protocols.get(dto.getProtocol()));
				if(StringUtils.isNotBlank(msInfoDto.getMeterModel())) {
					msInfoDto.setMeterModelName(modelList.stream().filter(y-> y.getId().equals(msInfoDto.getMeterModel())).findFirst().orElse(new MeterModelVO()).getModelName());
				}else {
					msInfoDto.setMeterModelName("");
				}
				setMsInfo(factory, msInfoDto, userInfo);
				return msInfoDto;
			}).collect(Collectors.toList());


			compareChange(msInfoDtoListBefore,msInfoDtoListAfter,userInfo,factory,bean.getId());


			BaseReceiptAccessoryMapper accessoryMapper = factory.getMapper(BaseReceiptAccessoryMapper.class);
			if(!StringUtils.isBlank(bean.getTempId()))		//修改附件ID
				accessoryMapper.updateAccessoryReceiptId(bean.getId(), bean.getTempId());
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("添加失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}


	public MsInfoDto setMsInfo(SessionFactory factory, MsInfoDto t, UserInfoBean userInfo) {

		MeterBoreMapper meterBoreMapper = factory.getMapper(MeterBoreMapper.class);
		MeterBoreBean boreBean = meterBoreMapper.selectMeterBoreById(t.getMeterBore());
		// 水表口径
		t.setMeterBoreName(boreBean == null?t.getMeterBore():boreBean.getBoreName());

		if(t.getValveControl() != null) {
			if(1 == t.getValveControl())
				t.setValveControlName("是");
			if(0 == t.getValveControl())
				t.setValveControlName("否");
		}

		//水表厂商
		MeterFactoryMapper meterFactoryMapper=factory.getMapper(MeterFactoryMapper.class);
		MeterFactoryBean factoryBean =  meterFactoryMapper.selectMeterFactoryById(t.getMeterFactory());
		// 水表厂家
		t.setMeterFactoryName(factoryBean==null?t.getMeterFactory():factoryBean.getFactoryName());
		//水表型号
		MeterModelMapper mapper = factory.getMapper(MeterModelMapper.class);
		MeterModelBean modelBean = mapper.selectMeterModelById(t.getMeterModel());
		t.setMeterModelName(modelBean ==null?t.getMeterModel():modelBean.getModelName());

		if (StringUtils.isNotBlank(t.getDepartBelong())) {
			//营业区域
			List<SelectVO> businessAreaList = factory.getMapper(BusinessAreaMapper.class).select(null, userInfo.getCurWaterCode());
//			// 营业网点
			//营业所
			for (SelectVO businessArea : businessAreaList) {
				if (businessArea.getId().equals(t.getDepartBelong())) {
					t.setDepartBelong(businessArea.getName());
					break;
				}
			}
		}
		return t;
	}


	public void compareChange(List<MsInfoDto> msInfoDtoListBefore,List<MsInfoDto> msInfoDtoListAfter,UserInfoBean userInfo,SessionFactory factory,String changeId){
		ArrayList<MsChangeHistoryBean> arrayList = new ArrayList<>();
		for (MsInfoDto msInfoDtoBefore : msInfoDtoListBefore) {
			//水表编号
			String meterNoBefore = msInfoDtoBefore.getMeterNo();
			//水表表身号
			String factoryNoBefore = msInfoDtoBefore.getFactoryNo();
			//水表型号
			String meterModelNameBefore = msInfoDtoBefore.getMeterModelName();
			//水表口径
			String meterBoreNameBefore = msInfoDtoBefore.getMeterBoreName();
			//水表厂家
			String meterFactoryNameBefore = msInfoDtoBefore.getMeterFactoryName();
			//水表分类
			String meterTypeNameBefore = msInfoDtoBefore.getMeterTypeName();
			//是否阀控
			String valveControlNameBefore = msInfoDtoBefore.getValveControlName();
			//下行规约
			String protocolNameBefore = msInfoDtoBefore.getProtocolName();
			//水表型式
			String meterPatternNameBefore = msInfoDtoBefore.getMeterPatternName();
			//水表传感器
			String meterSensorNameBefore = msInfoDtoBefore.getMeterSensorName();
			//满值
			BigDecimal maxValueBefore = msInfoDtoBefore.getMaxValue();
			//使用期限
			int shelfLifeBefore = msInfoDtoBefore.getShelfLife();
			//新旧表
			String meterFormNameBefore = msInfoDtoBefore.getMeterFormName();
			//合格证号
			String meterCertBefore = msInfoDtoBefore.getMeterCert();
			//所属部门
			String departBelongNameBefore = msInfoDtoBefore.getDepartBelongName();
			//imei
			String imeiBefore = msInfoDtoBefore.getImei();
			//imsi
			String imsiBefore = msInfoDtoBefore.getImsi();
			// sim
			String simBefore = msInfoDtoBefore.getSim();
			for (MsInfoDto msInfoDtoAfter : msInfoDtoListAfter) {
				String meterNoAfter = msInfoDtoAfter.getMeterNo();
				String factoryNoAfter = msInfoDtoAfter.getFactoryNo();
				String meterModelNameAfter = msInfoDtoAfter.getMeterModelName();
				String meterBoreNameAfter = msInfoDtoAfter.getMeterBoreName();
				String meterFactoryNameAfter = msInfoDtoAfter.getMeterFactoryName();
				String meterTypeNameAfter = msInfoDtoAfter.getMeterTypeName();
				String valveControlNameAfter = msInfoDtoAfter.getValveControlName();
				String protocolNameAfter = msInfoDtoAfter.getProtocolName();
				String meterPatternNameAfter = msInfoDtoAfter.getMeterPatternName();
				String meterSensorNameAfter = msInfoDtoAfter.getMeterSensorName();
				BigDecimal maxValueAfter = msInfoDtoAfter.getMaxValue();
				int shelfLifeAfter = msInfoDtoAfter.getShelfLife();
				String meterFormNameAfter = msInfoDtoAfter.getMeterFormName();
				String meterCertAfter = msInfoDtoAfter.getMeterCert();
				String departBelongNameAfter = msInfoDtoAfter.getDepartBelongName();
				String imeiAfter = msInfoDtoAfter.getImei();
				String imsiAfter = msInfoDtoAfter.getImsi();
				String simAfter = msInfoDtoAfter.getSim();
				if (meterNoAfter.equals(meterNoBefore)){
					if ((StringUtils.isNotEmpty(factoryNoBefore)&&!factoryNoBefore.equals(factoryNoAfter))||(StringUtils.isEmpty(factoryNoBefore)&&StringUtils.isNotEmpty(factoryNoAfter))) {
						saveMsChangeHistory(factoryNoBefore,factoryNoAfter,arrayList,"水表表身号",userInfo,meterNoAfter);
					}if (!Objects.equals(meterModelNameBefore, meterModelNameAfter)){

						saveMsChangeHistory(meterModelNameBefore,meterModelNameAfter,arrayList,"水表型号",userInfo,meterNoAfter);
					}if ((StringUtils.isNotEmpty(meterBoreNameBefore)&&!meterBoreNameBefore.equals(meterBoreNameAfter))||(StringUtils.isEmpty(meterBoreNameBefore)&&StringUtils.isNotEmpty(meterBoreNameAfter))){

						saveMsChangeHistory(meterBoreNameBefore,meterBoreNameAfter,arrayList,"水表口径",userInfo,meterNoAfter);
					}if ((StringUtils.isNotEmpty(meterFactoryNameBefore)&&!meterFactoryNameBefore.equals(meterFactoryNameAfter))||(StringUtils.isEmpty(meterFactoryNameBefore)&&StringUtils.isNotEmpty(meterFactoryNameAfter))){

						saveMsChangeHistory(meterFactoryNameBefore,meterFactoryNameAfter,arrayList,"水表厂家",userInfo,meterNoAfter);
					}if ((StringUtils.isNotEmpty(meterTypeNameBefore)&&!meterTypeNameBefore.equals(meterTypeNameAfter))||(StringUtils.isEmpty(meterTypeNameBefore)&&StringUtils.isNotEmpty(meterTypeNameAfter))){

						saveMsChangeHistory(meterTypeNameBefore,meterTypeNameAfter,arrayList,"水表分类",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(valveControlNameBefore)&&!valveControlNameBefore.equals(valveControlNameAfter))||(StringUtils.isEmpty(valveControlNameBefore)&&StringUtils.isNotEmpty(valveControlNameAfter))){

						saveMsChangeHistory(valveControlNameBefore,valveControlNameAfter,arrayList,"是否阀控",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(protocolNameBefore)&&!protocolNameBefore.equals(protocolNameAfter))||(StringUtils.isEmpty(protocolNameBefore)&&StringUtils.isNotEmpty(protocolNameAfter))){
						saveMsChangeHistory(protocolNameBefore,protocolNameAfter,arrayList,"下行规约",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(meterPatternNameBefore)&&!meterPatternNameBefore.equals(meterPatternNameAfter))||(StringUtils.isEmpty(meterPatternNameBefore)&&StringUtils.isNotEmpty(meterPatternNameAfter))){
						saveMsChangeHistory(meterPatternNameBefore,meterPatternNameAfter,arrayList,"水表型式",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(meterSensorNameBefore)&&!meterSensorNameBefore.equals(meterSensorNameAfter))||(StringUtils.isEmpty(meterSensorNameBefore)&&StringUtils.isNotEmpty(meterSensorNameAfter))){
						saveMsChangeHistory(meterSensorNameBefore,meterSensorNameAfter,arrayList,"水表传感器",userInfo,meterNoAfter);
					}
					if ((maxValueBefore !=null&&!maxValueBefore.equals(maxValueAfter))||(maxValueBefore ==null&&maxValueAfter !=null)){
						saveMsChangeHistory(String.valueOf(maxValueBefore),String.valueOf(maxValueAfter),arrayList,"满值",userInfo,meterNoAfter);
					}

					if (shelfLifeBefore !=shelfLifeAfter){
						saveMsChangeHistory(String.valueOf(shelfLifeBefore),String.valueOf(shelfLifeAfter),arrayList,"使用期限",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(meterFormNameBefore)&&!meterFormNameBefore.equals(meterFormNameAfter))||(StringUtils.isEmpty(meterFormNameBefore)&&StringUtils.isNotEmpty(meterFormNameAfter))){
						saveMsChangeHistory(meterFormNameBefore,meterFormNameAfter,arrayList,"新旧表",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(meterCertBefore)&&!meterCertBefore.equals(meterCertAfter))||(StringUtils.isEmpty(meterCertBefore)&&StringUtils.isNotEmpty(meterCertAfter))){
						saveMsChangeHistory(meterCertBefore,meterCertAfter,arrayList,"合格证号",userInfo,meterNoAfter);

					}
//					if ((StringUtils.isNotEmpty(meterStatusNameBefore)&&!meterStatusNameBefore.equals(meterStatusNameAfter))||(StringUtils.isEmpty(meterStatusNameBefore)&&StringUtils.isNotEmpty(meterStatusNameAfter))){
//						saveMsChangeHistory(meterStatusNameBefore,meterStatusNameAfter,arrayList,"水表状态",userInfo,meterNoAfter);
//
//					}
					if ((StringUtils.isNotEmpty(departBelongNameBefore)&&!departBelongNameBefore.equals(departBelongNameAfter))||(StringUtils.isEmpty(departBelongNameBefore)&&StringUtils.isNotEmpty(departBelongNameAfter))){
						saveMsChangeHistory(departBelongNameBefore,departBelongNameAfter,arrayList,"所属部门",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(imeiBefore)&&!imeiBefore.equals(imeiAfter))||(StringUtils.isEmpty(imeiBefore)&&StringUtils.isNotEmpty(imeiAfter))){
						saveMsChangeHistory(imeiBefore,imeiAfter,arrayList,"imei",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(imsiBefore)&&!imsiBefore.equals(imsiAfter))||(StringUtils.isEmpty(imsiBefore)&&StringUtils.isNotEmpty(imsiAfter))){
						saveMsChangeHistory(imsiBefore,imsiAfter,arrayList,"imsi",userInfo,meterNoAfter);
					}
					if ((StringUtils.isNotEmpty(simBefore)&&!imsiBefore.equals(simAfter))||(StringUtils.isEmpty(simBefore)&&StringUtils.isNotEmpty(simAfter))){
						saveMsChangeHistory(simBefore,simAfter,arrayList,"sim",userInfo,meterNoAfter);
					}
				}
			}
		}

		MsChangeHistoryMapper mapper = factory.getMapper(MsChangeHistoryMapper.class);
		if (CollectionUtils.isNotEmpty(arrayList)){
			arrayList.forEach(dto->{
				dto.setChangeId(changeId);
				dto.setId(Tools.getObjectId());
				dto.setCreateAccount(userInfo.getUserInfo().getAcount());
				dto.setCreateName(userInfo.getUserInfo().getName());
				dto.setTenantId(userInfo.getCurWaterCode());
				dto.setCreateTime(DateUtils.parseDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
			});
			Integer num = mapper.batchInsert(arrayList);

		}

	};
	public void saveMsChangeHistory(String changeBefore,String changeAfter,List<MsChangeHistoryBean> arrayList,String changeItem,UserInfoBean userInfo,String meterNo){
		MsChangeHistoryBean msChangeHistoryBean = new MsChangeHistoryBean();
		msChangeHistoryBean.setMeterNo(meterNo);
		msChangeHistoryBean.setChangeItem(changeItem);
		msChangeHistoryBean.setOldItemValue(changeBefore);
		msChangeHistoryBean.setNewItemValue(changeAfter);
		arrayList.add(msChangeHistoryBean);
	}

	private Boolean msInfoBeanIsRepeat(List<MsInfoBean> orderList) {
        Set<MsInfoBean> set = new TreeSet<MsInfoBean>(new Comparator<MsInfoBean>() {
            public int compare(MsInfoBean a, MsInfoBean b) {
                // 字符串则按照asicc码升序排列
                return a.getFactoryNo().compareTo(b.getFactoryNo());
            }
        });
        set.addAll(orderList);
        if (set.size() < orderList.size()) {
            return true;
        }
        return false;
    }

	private MsInfoBean imeiIsRepeat(List<MsInfoBean> list) {
		for (int i = 0; i < list.size(); i++){
			MsInfoBean msInfo1 = list.get(i);
			if (StringUtils.isBlank(msInfo1.getImei()))continue;
			for (int j = i + 1; j < list.size(); j++){
				MsInfoBean msInfo2 = list.get(j);
				if (StringUtils.isBlank(msInfo2.getImei()))continue;
				if (Objects.equals(msInfo1.getImei(), msInfo2.getImei())){
					return msInfo1;
				}
			}
		}
		return null;
	}

	private MsInfoBean imsiIsRepeat(List<MsInfoBean> list) {
		for (int i = 0; i < list.size(); i++){
			MsInfoBean msInfo1 = list.get(i);
			if (StringUtils.isBlank(msInfo1.getImsi()))continue;
			for (int j = i + 1; j < list.size(); j++){
				MsInfoBean msInfo2 = list.get(j);
				if (StringUtils.isBlank(msInfo2.getImsi()))continue;
				if (Objects.equals(msInfo1.getImsi(), msInfo2.getImsi())){
					return msInfo1;
				}
			}
		}
		return null;
	}
}
